#!/usr/bin/nawk
# Sum and average a column of numbers
# usage: if numbers are in column 1:
# gawk -f average.awk 1 data.in
BEGIN {
  n = ARGV[1];
  ARGV[1] = "";
  max = -1e38;
  min = 1e38;
  count = 0;
 
}

{
  if($n > max) max = $n;
  if($n < min) min = $n;
  if($n > 0) count++;
  sum += $n;
  sumq += $n * $n;
}
  
END {
  if(NR > 0){
    average = sum/NR;
    sigq = sumq / NR - average * average;
    if(sigq > 0){
      sigma = sqrt(sigq);
    }
    else sigma = 0;

#special adj for 3d wind speed.  If negative set to 0
#    if (average < 0){
#	adj_average = -999;
#    }
#    else adj_average = average;
	
#    if (adj_average == -999){
    printf("%10.2f\t %d\t %d\n", average, count, NR);
#    }
#    else printf("%10.2f\t %10.2f\t %d\n", average, adj_average, NR);
  }
   
}
